package com.cqc.pgy01;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.AndroidCharacter;
import android.util.Log;
import android.view.View;

import com.pgyersdk.activity.FeedbackActivity;
import com.pgyersdk.feedback.PgyFeedback;
import com.pgyersdk.feedback.PgyFeedbackShakeManager;

/**
 * Created by cui on 2017/1/8.
 */

public class BaseActivity extends AppCompatActivity {

    //    private final String TAG = getClass().getSimpleName().toString();
    private final String TAG = "BaseActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    /**
     * activity的生命周期保证了子类一定走父类的这个方法
     */
    @Override
    protected void onResume() {
        super.onResume();
        // 自定义摇一摇的灵敏度，默认为950，数值越小灵敏度越高。
        PgyFeedbackShakeManager.setShakingThreshold(300);

        // 以对话框的形式弹出
        PgyFeedbackShakeManager.register(this);

        // 以Activity的形式打开，这种情况下必须在AndroidManifest.xml配置FeedbackActivity
        // 打开沉浸式,默认为false
        // FeedbackActivity.setBarImmersive(true);
        //        PgyFeedbackShakeManager.register(this, false);
    }

    public void initFAB2() {
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "fab onClick");
                initTABClick();
            }
        });
    }

//    public FloatingActionButton initFAB() {
//        FloatingActionButton fab = new FloatingActionButton(this);
//        //        fab.setActivated(true);
//        fab.setRight(20);
//        fab.setBottom(20);
//        fab.setImageResource(android.R.drawable.ic_input_add);
//        fab.show();
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Log.d(TAG, "fab onClick");
//                initTABClick();
//            }
//        });
//        return fab;
//    }


    public Toolbar initToolbar(String title) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(title);
        setSupportActionBar(toolbar);
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);

        }
        return toolbar;
    }

    private void initTABClick() {
        FeedbackActivity.setBarImmersive(true);
        PgyFeedback.getInstance().showActivity(BaseActivity.this);
    }


    @Override
    protected void onPause() {
        super.onPause();
        PgyFeedbackShakeManager.unregister();
    }
}
